<template>
  <div class="Withdrawal">
    <!-- 提现金额 -->
    <div class="Withdrawal_cont">
      <p>可提现金额</p>
      <p>{{ $common.formatMoney(amountKe) }}</p>
    </div>
    <!-- 提现姓名 -->
    <div class="Withdrawal_input">
      <van-cell-group>
        <van-field v-model="username" label="姓名：" />
      </van-cell-group>
      <p>温馨提示：请填写提现人真实姓名</p>
    </div>
    <!-- 金额 -->
    <div class="Withdrawal_input">
      <van-cell-group>
        <van-field
          v-model="amount"
          @input="changeAmount"
          type="digit"
          label="金额："
        />
      </van-cell-group>
      <!-- <p>温馨提示：请填写提现金额,提现手续费2%</p> -->
    </div>
    <!-- <div class="tips" v-if="serviceCharge > 0">
      <p>提现手续分为 {{ serviceCharge }}</p>
    </div> -->
    <div class="Withdrawal_button">
      <van-button
        block
        color="#D2A166"
        @click="applyUserWithdraw"
        type="primary"
        >确定</van-button
      >
    </div>
  </div>
</template>

<script lang="ts">
import { Vue, Component, Prop } from "vue-property-decorator";
import { Button, Field, CellGroup, Toast } from "vant";

Vue.use(CellGroup);
Vue.use(Field);
Vue.use(Button);
@Component({})
export default class Withdrawal extends Vue {
  private username: string = "";
  private amount: number = 0;
  private amountKe = this.$route.params.id;
  private serviceCharge:string = '0';
  private changeAmount(e: number) {
    this.serviceCharge = (e * 0.02).toFixed(2);
  }

  private applyUserWithdraw(): void {
    if (this.username == "") {
      Toast(`姓名是必填的！`);
      return;
    }
    if (this.amount == undefined) {
      Toast(`金额是必填的！`);
      return;
    }
    if (this.amount < 100) {
      Toast(`金额大于100才能提现！`);
      return;
    }
    if((this.amount+this.serviceCharge)>this.amountKe){
       Toast(`提现金额加手续费不能大于可提现金额`);
      return;
    }
    this.$post(`applyUserWithdraw`, {
      amount: this.amount * 100,
      username: this.username,
    }).then((res: any) => {
      if (res.code == 0) {
        Toast(`提现成功！`);
      }
    });
  }
}
</script>

<style lang="scss" scope>
.Withdrawal {
  width: 100%;
  padding: 20px;
  box-sizing: border-box;
  .Withdrawal_cont {
    width: 100%;
    height: 200px;
    border-radius: 15px;
    background-image: url("~@/assets/MyWallet.png");
    background-position: center;
    background-repeat: no-repeat;
    background-size: 100% 100%;
    padding: 50px;
    box-sizing: border-box;
    p {
      font-size: 36px;
      font-weight: 300;
      color: #ffffff;
      line-height: 1.3;
    }
  }
  .Withdrawal_input {
    width: 100%;
    padding: 20px;
    box-sizing: border-box;
    background-color: #ffffff;
    border-radius: 10px;
    margin-top: 40px;
    .van-field__label {
      width: 45px;
    }
    .van-cell__value {
      border-bottom: 1px solid #333333;
    }
    p {
      color: #999999;
      padding-left: 30px;
      box-sizing: border-box;
    }
  }
  .tips {
    width: 100%;
    margin: 20px 0;
    p {
      color: red;
      line-height: 1.5;
    }
  }
  .Withdrawal_button {
    position: fixed;
    width: 100%;
    left: 0;
    bottom: 0;
  }
}
</style>